package iotest;

import java.io.*;

public class PwDemo {
    public static void main(String[] args) {
        //
        //字符缓冲流
        //1. 直接使用
        PrintWriter pw= null;
        try {
            pw = new PrintWriter("pw.txt");
            pw.println("one");
            pw.println("two");
            System.out.println("写入完毕!");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } finally {
            pw.close();
        }
        //2. 4层流连接
        //文件流
        FileOutputStream fos= null;
        try {
            fos = new FileOutputStream("pw.txt");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        //字符转换流
        OutputStreamWriter osw=new OutputStreamWriter(fos);
        //字符缓冲流
        BufferedWriter bw=new BufferedWriter(osw);
        //字符输出流
        PrintWriter pw2=new PrintWriter(bw);
        pw.println("哒，哒~~~~");
        pw.println("哒，哒~~~~");
        System.out.println("写入完毕!");
        pw.close();



    }
}
